import java.util.Arrays;

class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(Student o) {
        return this.name.compareTo(o.name);
    }

 /*   @Override
    public int compareTo(Student o) {
        return this.age-o.age;
    }*/

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test {
    public static void mySort(Comparable[] comparables) {
        for (int i = 0; i < comparables.length - 1; i++) {
            for (int j = 0; j < comparables.length - 1 - i; j++) {
                //if(comparables[j] > comparables[j+1]) {
                if (comparables[j].compareTo(comparables[j + 1]) > 0) {
                    //交换
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j + 1];
                    comparables[j + 1] = tmp;
                }
            }
        }
    }
    public static void main(String[] args) {
      /*  Student student1=new Student("zhangsan",18);
        Student student2=new Student("lisi",20);
        if (student1.compareTo(student2)>0){
            System.out.println("student1");
        }
        else{
            System.out.println("student2");
        }*/
        Student[] students=new Student[3];
        students[0]=new Student("zhsnanv",13);
        students[1]=new Student("lisi",20);
        students[2]=new Student("wangqu",18);
        mySort(students);
        System.out.println(Arrays.toString(students));
    }
}
